<template>
  <div class="content travelFootprints">
    <!--导航模块-->
    <THeader :active="this.$route.path"></THeader>
    <!--内容模块-->
    <el-row style="padding: 40px 0;">
      <el-col :span="18" :offset="3" class="body-card">
        <h3 style="cursor: pointer" @click="routerBack">
          <i class="el-icon-arrow-left"></i>发表游记</h3>
        <Divider/>
        <el-form ref="form" :model="reportForm" label-width="80px">
          <el-form-item label="游记标题">
            <el-input placeholder="输入标题" v-model="reportForm.title"></el-input>
          </el-form-item>
          <el-form-item label="分类">
            <el-select placeholder="选择分类" v-model="reportForm.tag">
              <el-option v-for="(item,index) in list" :key="index" :label="item.name" :value="item.key">{{item.name}}</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="游记内容">
            <el-input placeholder="输入内容" v-model="reportForm.text" type="textarea" :rows="12"></el-input>
          </el-form-item>
          <el-form-item style="text-align: right">
            <el-button style="width: 120px" @click="routerBack">取消</el-button>
            <el-button @click="reportNoteAction" style="width: 120px">提交</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { articleServer } from "../../api/notes"; //旅游足迹
export default {
  name: "travelFootprints",
  data() {
    return {
      reportForm: {
        title: "",
        tag: "",
        text: ""
      },
      items: [],
      list: [
        { key: "inbound", name: "国内游" },
        { key: "abroad", name: "出境游" },
        { key: "spot", name: "热门景点" },
        { key: "shopping", name: "购物圣地" },
        { key: "article", name: "旅游文摘" }
      ]
    };
  },
  methods: {
    routerBack() {
      this.$router.push({ path: "/travel-notes" });
    },
    reportNoteAction() {
      articleServer("post", { ...this.reportForm, state: 1 }).then(
        suc => {
          const { code, message } = suc.data;
          if (code) {
            this.$message({
              type: "success",
              message
            });
            this.routerBack();
          } else {
            this.$message({
              type: "error",
              message
            });
          }
        },
        err => {
          this.$message({
            type: "error",
            message: err.message
          });
        }
      );
    }
  }
};
</script>